package com.cqc.crm.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.cqc.crm.domain.Dict;
import com.cqc.crm.service.DictService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class DictAction extends ActionSupport implements ModelDriven<Dict> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -802737993441745930L;
	private Dict dict = new Dict();
	@Override
	public Dict getModel() {
		return dict;
	}

	private DictService dictService;
	public void setDictService(DictService dictService) {
		this.dictService = dictService;
	}

	public void findDictByCode() {
		//查找字典表》List
		List<Dict> list=dictService.findDictByCode(dict.getDict_type_code());
		//转换成json+传递json
		String json=JSON.toJSONString(list, SerializerFeature.DisableCircularReferenceDetect);
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("text/html;charset=utf8");
		response.setCharacterEncoding("utf-8");
		PrintWriter writer;
		try {
			writer = response.getWriter();
			writer.println(json);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
